#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;

class Solution {
public:
    int isPrefixOfWord(string sentence, string searchWord) {
        int count = 0;
        for (int i = 0; i < sentence.size(); ++i)
        {
            if (sentence[i] != ' ')
            {
                ++count;
                for (int j = i; sentence[j] != ' ' && sentence[j] != '\0'; ++j)
                {
                    if (sentence[j] != searchWord[j - i])
                    {
                        while (sentence[++j] != ' ' && sentence[j] != '\0');
                        i = j;
                        break;
                    }
                    if (searchWord[j - i + 1] == '\0')
                    {
                        return count;
                    }
                    if (sentence[j + 1] == ' ' || sentence[j + 1] == '\0')
                    {
                        i = j + 1;
                        break;
                    }
                }
            }
        }
        return -1;
    }
};

int main()
{
    string sen("b bu bur burg burger");
    string sear("burg");
    cout << Solution().isPrefixOfWord(sen, sear) << endl;


    return 0;
}